#!/bin/bash

Tail=""
prj="VesselOS:1.0:LTS:SP1"
repo="standard_x86_64"
arch="x86_64"
opts=

usage()
{
    echo "$0 [-t] [-l ] [-p <project>] [-a <arch>] [-r <repository>] <package>"
    echo "-t: tail log"
    echo "-l: show last build log"
    echo "-p: project, default: ${prj}"
    echo "-a: arch, default: ${arch}"
    echo "-r: repository, defualt: ${repo}"
}

if [ $# -lt 1 ]; then
    usage
    exit 1
fi

while getopts ":p:a:r:tlh" opt
do
    case $opt in
    h)
        usage
	;;
    l)
        opts="$opts -l"
        ;;
    t)
        Tail="yes"
        ;;
    p)
        prj=${OPTARG}
        ;;
    a)
        arch=${OPTARG}
        ;;
    r)
        repo=${OPTARG}
        ;;
    ?)
        echo "unknown option $OPTARG"
        ;;
    esac
done

shift $(($OPTIND - 1))

pkg=$1

if [ -n "$Tail" ]; then
    osc rblt $opts ${prj} ${pkg} ${repo} ${arch}
else
    osc rbl $opts ${prj} ${pkg} ${repo} ${arch}
fi
